package Utils;

import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.util.SystemPropertyUtils;

public class SpringBeanUtil {

	private static GenericApplicationContext context;

	static {
		context = new GenericApplicationContext();
		XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context);
		xmlReader.loadBeanDefinitions(SystemPropertyUtils.resolvePlaceholders("classpath:*.xml"));
		context.refresh();
		context.registerShutdownHook();
	}

	@SuppressWarnings("unchecked")
	public static <T> T getBean(String beanName) {
		return (T) context.getBean(beanName);
	}
}
